package demo03;

import demo02.FoodManager;

import java.util.Scanner;

public class Client {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        FilmManager fim=new FilmManager();

        while (true){
            System.out.println("1）添加新电影");
            System.out.println("2）修改电影状态");
            System.out.println("3）查看所有已上架的电影信息");
            System.out.println("4）查看所有以下架的电影信息");
            System.out.println("5）退出");
            int choose = input.nextInt();
            switch (choose) {
                case 1:
                    addFilm(input, fim);
                    break;
                case 2:
                    updateFilm(input, fim);
                    break;
                case 3:
                    System.out.println("1.根据评分排序查看  2.根据价格排序查看");
                    int state= input.nextInt();
                    printFilm(fim.selectIsOnline(state));
                    break;
                case 4:
                    System.out.println("1.根据评分排序查看  2.根据价格排序查看");
                    int state1= input.nextInt();
                    printFilm(fim.selectNoOnline(state1));
                    break;
                case 5:
                    System.out.println("谢谢使用，再见");
                    return;
                default:
                    System.out.println("输入有误，请重新输入！");
            }
        }
    }

    private static void updateFilm(Scanner input, FilmManager fim) {
        System.out.println("请输入你要修改的电影名");
        String fName= input.next();
        if (fim.updateFilm(fName)){
            System.out.println("修改成功");
        }else{
            System.out.println("该电影不存在");
        }
    }

    private static void addFilm(Scanner input, FilmManager fim) {
        System.out.println("请输入电影名");
        String fname= input.next();
        System.out.println("是否上架");
        String isOnline= input.next();
        System.out.println("请输入评分");
        double score= input.nextDouble();
        System.out.println("请输入票价");
        double price= input.nextDouble();

        Film film1=new Film(fname,isOnline,score,price);
        boolean add= fim.addFilm(film1);
        System.out.println(add ? "添加电影成功!":"添加电影失败!");
    }


    private static void printFilm(Film[] films) {
        System.out.println("电影标号\t\t|电影名称\t\t|电影状态\t\t|电影评分\t\t|电影价格");
        for (int i = 0; i < films.length; i++) {
            Film f = films[i];
            String str = String.format("%d\t\t|%s\t\t|%s\t\t|%.2f\t\t|%.2f",f.getfId(),f.getfName(),f.getIsOnline(),f.getScore(),f.getPrice());
            System.out.println(str);
            //System.out.println(s.getStuId() + "\t" + s.getName() + "\t" + s.getAge() + "\t" + s.getGender() + "\t" + s.getPhone());
        }
    }
}
